package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.ParkMachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 停车点车辆绑定
 *
 * @author Leon
 * 2017年2月24日 下午5:51:05
 */
@Validated
@RestController
@RequestMapping(value = "/parkMachine", produces = BaseController.MEDIA_JSON_UTF8)
public class ParkMachineController extends BaseController {
    @Autowired
    private ParkMachineService parkMachineService;

    /* 批量投放*/
    @RequestMapping("/deliverBatch")
    public JsonResult deliverBatch(@NotNull(message = "ver.parkPointId.notNull") Integer parkPointId,
                                   @NotNull(message = "ver.machineNOs.notNull") String machineNOs,
                                   HttpServletRequest request) {
        LoginInfo info = getLogin(request);
        List<String> machineNOArray = Arrays.asList(machineNOs.split(","));

        Map<Integer, List<String>> errorMap = parkMachineService.deliverBatch(info, parkPointId, machineNOArray);
        HashMap<String, Object> params = new HashMap<>();
        if (errorMap.containsKey(1)) {
            params.put("errorMap", errorMap.get(1));
        } else if (errorMap.containsKey(2)) {
            params.put("errorMap", errorMap.get(2));
        }

        return JsonResult.ok(errorMap);
    }


}